{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 描述\n",
    "Python continue 语句**跳出本次循环**，而break跳出整个循环。\n",
    "\n",
    "continue 语句用来告诉Python跳过当前循环的剩余语句，然后继续进行下一轮循环。\n",
    "\n",
    "continue语句用在while和for循环中。\n",
    "\n",
    "# 语法\n",
    "Python 语言 continue 语句语法格式如下：\n",
    "```\n",
    "continue\n",
    "```\n",
    "\n",
    "# 流程图：\n",
    "\n",
    "![continue-流程图](https://pptwinpics.oss-cn-beijing.aliyuncs.com/continue-%E6%B5%81%E7%A8%8B%E5%9B%BE_20191126150030.jpg)\n",
    "\n",
    "# 实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前字母 : P\n",
      "当前字母 : y\n",
      "当前字母 : t\n",
      "当前字母 : o\n",
      "当前字母 : n\n",
      "当前变量值 : 9\n",
      "当前变量值 : 8\n",
      "当前变量值 : 7\n",
      "当前变量值 : 6\n",
      "当前变量值 : 4\n",
      "当前变量值 : 3\n",
      "当前变量值 : 2\n",
      "当前变量值 : 1\n",
      "当前变量值 : 0\n",
      "Good bye!\n"
     ]
    }
   ],
   "source": [
    "for letter in 'Python':     # 第一个实例\n",
    "   if letter == 'h':\n",
    "      continue\n",
    "   print('当前字母 :', letter)\n",
    " \n",
    "var = 10                    # 第二个实例\n",
    "while var > 0:              \n",
    "   var = var -1\n",
    "   if var == 5:\n",
    "      continue\n",
    "   print('当前变量值 :', var)\n",
    "print(\"Good bye!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 其他实例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "3\n",
      "5\n",
      "7\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "# 我们想只打印0-10之间的奇数，可以用continue语句跳过某些循环：\n",
    "\n",
    "n = 0\n",
    "while n < 10:\n",
    "    n = n + 1\n",
    "    if n % 2 == 0:      # 如果n是偶数，执行continue语句\n",
    "        continue        # continue语句会直接继续下一轮循环，后续的print()语句不会执行\n",
    "    print(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前值 : 9\n",
      "当前值 : 7\n",
      "当前值 : 6\n",
      "当前值 : 4\n",
      "当前值 : 3\n",
      "当前值 : 2\n",
      "当前值 : 1\n",
      "当前值 : 0\n",
      "Good bye!\n"
     ]
    }
   ],
   "source": [
    "# continue 语句是一个删除的效果，他的存在是为了删除满足循环条件下的某些不需要的成分\n",
    "\n",
    "var = 10\n",
    "\n",
    "while var > 0:\n",
    "    var = var -1\n",
    "    if var == 5 or var == 8:\n",
    "        continue\n",
    "    print('当前值 :', var)\n",
    "print(\"Good bye!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
